package com.startupwebapp.core.domain.users;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.directwebremoting.annotations.DataTransferObject;
import org.directwebremoting.annotations.Filter;
import org.directwebremoting.annotations.Param;
import org.directwebremoting.annotations.RemoteProperty;
import org.directwebremoting.hibernate.H3BeanConverter;
import org.directwebremoting.hibernate.H3SessionAjaxFilter;
import org.hibernate.annotations.CollectionOfElements;

/**
 * User entity. @author MyEclipse Persistence Tools
 */
@Entity
@Table(name = "person")
@DataTransferObject(type = "hibernate3", converter = H3BeanConverter.class, params = @Param(name = "assumeSession", value = "true"))
@Filter(type = H3SessionAjaxFilter.class)
public class Person {
	@SequenceGenerator(name = "Seq_Gen", sequenceName = "Seq_Gen_Id")
	@RemoteProperty
	@Id
	@GeneratedValue(generator = "Seq_Gen")
	@Column(name = "id", unique = true, nullable = false)
	private Integer id;
	// Fields
	@GeneratedValue
	@Column(name = "login", unique = true)
	private String login;
	@Column(name = "active", nullable = false)
	private boolean active = true;
	@RemoteProperty
	@Column(name = "first_name", nullable = false, length = 50)
	private String firstName;
	@RemoteProperty
	@Column(name = "last_name", nullable = false, length = 50)
	private String lastName;
	@RemoteProperty
	@CollectionOfElements
	private List<PersonRole> roles;
	@Column(name = "passwordHash", nullable = false)
	private String passwordHash;
	@RemoteProperty
	@Column(name = "email", nullable = false, unique = true)
	private String email;
	@RemoteProperty
	private Date registrationDate = new Date();

	public Person() {
	}

	public Person(List<PersonRole> roles, boolean active, String firstName,
			String lastName, String login, String passwordHash) {
		this.roles = roles;
		this.active = active;
		this.firstName = firstName;
		this.lastName = lastName;
		this.login = login;
		this.passwordHash = passwordHash;
	}

	// TODO: generate in database, or user @Temporal annotation
	public Date getRegistrationDate() {
		return registrationDate;
	}

	public void setRegistrationDate(Date registrationDate) {
		this.registrationDate = registrationDate;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getPasswordHash() {
		return passwordHash;
	}

	public void setPasswordHash(String passwordHash) {
		this.passwordHash = passwordHash;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public boolean getActive() {
		return this.active;
	}

	public String getFirstName() {
		return this.firstName;
	}

	// Property accessors

	public Integer getId() {
		return this.id;
	}

	public String getLastName() {
		return this.lastName;
	}

	public List<PersonRole> getRoles() {
		return this.roles;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public void setRoles(List<PersonRole> roles) {
		this.roles = roles;
	}

}